package com.zy.dao;

import com.zy.entity.Video;
import com.zy.entity.VideoText;
import com.zy.entity.VideoType;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 张宇
 * @date 2021/7/30 17:47
 */
@Mapper
public interface HomeMapper
{

    /**
     * 通过parentId查询集合
     * @param parentId
     * @return
     */
    @Select("select * from videoweb_type where parent_id = #{parentId}")
    public List<VideoType> findVideoListByParentId(int parentId);

    /**
     * 增加视频信息
     * @param video
     */
    @Insert("insert into videoweb_video(video_title, video_src, img_src, video_type, user_id, exp, create_time, video_view) values(#{videoTitle}, #{videoSrc}, #{imgSrc}, #{videoType}, #{userId}, #{explain}, #{createTime}, #{videoView})")
    public void addVideo(Video video);

    /**
     * 首页最新的视频
     * @return
     */
    @Select("select videoweb_video.id, videoweb_video.video_title, videoweb_video.video_src, videoweb_video.img_src, " +
            "videoweb_type.type_name , videoweb_user.username, videoweb_user.head_img, videoweb_video.exp `explain`, " +
            "videoweb_video.create_time, videoweb_video.video_view, videoweb_video.status  from videoweb_video " +
            "inner join videoweb_type on videoweb_video.video_type = videoweb_type.id " +
            "inner join videoweb_user on videoweb_video.user_id = videoweb_user.id " +
            "where videoweb_video.status = #{status} " +
            "order by videoweb_video.create_time desc " +
            "limit #{Begin}, #{PageSize}")
    public List<VideoText> videoListByBeginAndPageSize(int Begin, int PageSize, String status);

    /**
     * 首页热门视频
     * @return
     */
    @Select("select videoweb_video.id, videoweb_video.video_title, videoweb_video.video_src, videoweb_video.img_src, " +
            "videoweb_type.type_name , videoweb_user.username, videoweb_user.head_img, videoweb_video.exp `explain`, " +
            "videoweb_video.create_time, videoweb_video.video_view, videoweb_video.status from videoweb_video " +
            "inner join videoweb_type on videoweb_video.video_type = videoweb_type.id " +
            "inner join videoweb_user on videoweb_video.user_id = videoweb_user.id " +
            "where videoweb_video.status = #{status} " +
            "order by videoweb_video.video_view desc " +
            "limit #{Begin}, #{PageSize}")
    public List<VideoText> hotVideoListByBeginAndPageSize(int Begin, int PageSize, String status);

    /**
     * 查询视频数量
     * @return
     */
    @Select("select count(*) from videoweb_video")
    public int videoNum();

    /**
     * 通过id查找视频信息
     * @param id
     * @return
     */
    @Select("select videoweb_video.id, videoweb_video.video_title, videoweb_video.video_src, videoweb_video.img_src, videoweb_type.type_name , videoweb_user.username, videoweb_user.head_img, videoweb_video.exp `explain`, videoweb_video.create_time, videoweb_video.video_view " +
            "from videoweb_video inner join videoweb_type on videoweb_video.video_type = videoweb_type.id" +
            "           inner join videoweb_user on videoweb_video.user_id = videoweb_user.id " +
            "           where videoweb_video.id = #{id}")
    public VideoText findVideoById(int id);

    /**
     * 通过id修改videoView的数量
     * @param id
     * @param videoView
     */
    @Update("update videoweb_video set video_view = #{videoView} where id = #{id}")
    public void addVideoViewById(Integer id, int videoView);

    /**
     * 得到自己的视频列表
     * @param userId
     * @return
     */
    @Select("select * from videoweb_video where user_id = #{userId}")
    public List<VideoText> getOneselfVideoList(@Param("userId") int userId);

}
